<%@ LANGUAGE="VBSCRIPT" %>
<%'  ------------------------------------------------------------
  '  foldercontent.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.69  $
  '  $Date:   05 Dec 2000 17:04:42  $
  '  $Author:   syu  $
  '  $Workfile:   foldercontent.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>
<!-- #include file="islogon.asp" -->
<!-- #include file="jscriptfix.asp" -->

<%
  'an IE browser?
  IEBrowser = InStr(Request.ServerVariables("HTTP_USER_AGENT"), "MSIE") > 0
  
  set oDocUtil = Server.CreateObject("IDMWeb.DocumentUtilities")
  
  LibraryLabel = Session("LibraryLabel")
  
  'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
  'whether the user has logged on.
  'Please see logoncall.asp to see how the Session variable LibraryLogonID is set.

  LibraryLogonID = Session("LibraryLogonID")
  set LibraryObj = Server.CreateObject("IDMObjects.Library")
  LibraryObj.LogonID = LibraryLogonID

  if LibraryObj.SystemType = Application("idmSysTypeIS") then 
    'If no previous ContentPathname, then assume root folder.
    ContentPathname = Session("ContentPathname")
    If ContentPathname = "" then
      ContentPathname = "/"
    End If

	'If a target FolderName is passed in, then parse out the target pathname.
    foldername = Request.QueryString("FolderName")

    If Left(foldername, 1) = "/" Then
	  'It's an absolute pathname
      ContentPathname = foldername
    ElseIf ContentPathname = "/" and foldername <> ".." Then
	  'Top level folder, so concatenate with the additional foldername
      ContentPathname = ContentPathname + foldername
    ElseIf foldername = ".." Then
	  'Parse out the parent pathname
      pos = 1
      Do
        currentpos = pos
	    pos = InStr(currentpos + 1, ContentPathname, "/")
      Loop while pos > 0
      If currentpos = 1 Then
        ContentPathname = "/"
      Else
	    ContentPathname = Left(ContentPathname, currentpos - 1)
      End If
    ElseIf Len(foldername) Then
	  'Just concatenate the folder pathname
	  ContentPathname = ContentPathname + "/" + foldername
    End If

    if ContentPathname = "/" then
	  IsFolder=0	' root
	  'We're going to display top-level folders
      set Folders = LibraryObj.TopFolders
    else
	  IsFolder=1	' folder
	  'Get to that folder
      On Error Resume Next
	  set ParentFolder = LibraryObj.GetObject(Application("idmObjTypeFolder"), ContentPathname)
	  if Len(Err.Description) then
			Response.Expires = 0
			' Response.Status = "404 Not Found"
			Response.ContentType = "text/plain"
			Response.Write "Error on get Folder: "
			Response.Write Err.Description
			Response.End
	   end if

	  'We're going to display Subfolders and Contents
      set Folders = ParentFolder.SubFolders
      set Docs = ParentFolder.GetContents(Application("idmFolderContentDocument"))
    end if
	'Keep track of the new pathname we are displaying
    Session("ContentPathname") = ContentPathname
  else ' LibraryObj.SystemType = Application("idmSysTypeDS")
    'If it's Document Services, we can only uniquely identify a folder by its ID.
    folderid = Request.QueryString("FolderName")
    if folderid = "" then
        folderid = Session("ContentPathname")
        if folderid = "" then
          folderid = "/"
         end if
    end if
    if folderid = LibraryObj.Name OR folderid = "/" then
		IsFolder=0	' root
	  'We're going to display top-level folders
      ContentPathname = "/"
      set Folders = LibraryObj.TopFolders
      
	  Session("ContentPathname") = "/"
    else
		IsFolder=1	' folder
	  'Get to that folder
      On Error Resume Next
	  set ParentFolder = LibraryObj.GetObject(Application("idmObjTypeFolder"), folderid)
	  if Len(Err.Description) then
			Response.Expires = 0
			' Response.Status = "404 Not Found"
			Response.ContentType = "text/plain"
			Response.Write "Error on get Folder: "
			Response.Write Err.Description
			Response.End
		end if

	  'We're going to display Subfolders and Contents
      set Folders = ParentFolder.SubFolders
      set Docs = ParentFolder.GetContents(Application("idmFolderContentDocument"))

      ContentPathname = ParentFolder.PathName
      Session("ContentPathname") = ParentFolder.Id
    end if
  end if
%>


<SCRIPT LANGUAGE="JavaScript">
<!--
// This function will be called when the user clicks a document icon.
function ShowDocument(docid, pages)
{
<% if LibraryObj.SystemType = Application("idmSysTypeIS") then 
  if Application("ViewUsingNativeApplication") then %>
    if (pages > 1)
    {
		var page = prompt ("This document has "+pages+" pages. Enter a page number: (1 - " + pages + " )", "1" );
		if (page != null)
		{
			//Document Content retrieval with Native Application viewing
			if (page > 0 && page <= pages)
			   parent.location.href = "doccontent.asp?DocID=" + docid + "&StartPage=" + page;	
			else
			   alert("Invalid page number.");
		}       
    } else
      // Document Content retrieval with Native Application viewing
      parent.location.href = "doccontent.asp?DocID=" + docid+ "&StartPage=1";
  <% else %>
     // Viewer Application as Active Document Server viewing
     parent.location.href = "docnavigate.asp?DocID=" + docid;
  <% end if %>

<% else %>

  // Document Content retrieval with Native Application viewing
  parent.location.href = "doccontent.asp?DocID=" + docid;

<% end if %>
}
//-->
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
<!--
// This function will be called when a folder icon is clicked on.
function ShowFolderContent(fname)
{
<% if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
  if (fname.charAt(0) == '/')
	location.href = "foldercontent.asp?Library=<%=Server.URLEncode(LibraryObj.Label)%>&FolderName=" + fname;
  else
	location.href = "foldercontent.asp?Library=<%=Server.URLEncode(LibraryObj.Label)%>&FolderName=" + <% if ContentPathName = "/" then %>"/"<% else %>"<%= ContentPathName %>/"<% end if %> + fname;
<% else %>
	location.href = "foldercontent.asp?Library=<%=Server.URLEncode(LibraryObj.Label)%>&FolderName=" + fname;
<% end if %>
}


// This function will be called when a property icon is clicked on.
function ShowProperty(type, ident)
{
  parent.location.href = "property.asp?Type=" + type + "&Ident=" + ident;
}
//-->
</SCRIPT>

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>
<head>
<title>ContentView</title>
<meta name="GENERATOR" content="Microsoft FrontPage 1.1">
</head>

<!-- %= Session("ContentPathname") %><br>
<%= foldername %><br> -->

<body bgcolor="#FFFFFF" topmargin=0 leftmargin=0>


  <table cellpadding=0 cellspacing=0 width=100%>
  <tr><td>
  <IMG SRC="images/library.jpg" WIDTH="44" HEIGHT="39" ALIGN="CENTER" NATURALSIZEFLAG="3">
  <strong><font size=4>
  <% 
  'Display the content pathname with each part represented as a link. This makes it easy to
  'navigate and refresh the view.
  if IsFolder=1 then
  %>
  <a HREF="javascript:ShowFolderContent('/')"><% end if %><%= LibraryLabel %>
  <% 
  if IsFolder=1 then%></a><% end if %>:</font>
<%	' IS libraries
	if LibraryObj.SystemType = Application("idmSysTypeIS") then %>

  <%
  'Parse out each section of the full pathname
  pos = 1
  Do
  currentpos = pos + 1
  pos = InStr(currentpos, ContentPathname, "/")
  if pos > 0 then
  	s = Mid(ContentPathname, currentpos, pos - currentpos)
  	a = Left(ContentPathname, pos - 1)
  %>
  <font size=3>/<a HREF="javascript:ShowFolderContent('<%=a%>')"><%= Server.HTMLEncode(s) %></a></font>
  <%
  end if
  Loop while pos > 0
  %>
  <font size=3>/<a HREF="javascript:ShowFolderContent('<%=ContentPathname%>')"><%= Server.HTMLEncode(Right(ContentPathname, Len(ContentPathname) - currentpos + 1)) %></a></font>
  </strong>
  </td>

<%  ' DS libraries
else 
  if IsFolder=1 then
    set FoldDict = Server.CreateObject("Scripting.Dictionary")
    i = 1
    set LoopFolder = ParentFolder

	'Traverse all the way up to the Library, and keep each level of folder in the dictionary.
    Do While LoopFolder.ID <> LibraryObj.Name
      FoldDict.Add i, LoopFolder
      set LoopFolder = LoopFolder.Parent
      i = i + 1
    Loop
    
	Dim Items
    Items = FoldDict.Items
	'Enumerate through all the folders in the dictionary
    for j = i - 1 to 1 Step - 1
      set FolderPart = FoldDict(j)
%>
    <font size=3>/<a HREF="javascript:ShowFolderContent('<%=FolderPart.ID%>')"><%=Server.HTMLEncode(FolderPart.Label)%></a></font>
<%
    next %>
  </strong>
  </td>
<%
   end if 
end if
%>
  <td align=right valign=bottom>
  <font size=2>
  <% 'Display the count of folders and documents
  if IsFolder=0 then %>
  (<%= Folders.Count %> folders)
  <% else %>
  (<%= Folders.Count %> folders, <%= Docs.Count %> documents)
  <% end if %>
  </font>
  </td></tr>
  </table>



<table cellpadding=0 cellspacing=1 width=100%>
<tr>
<td BGCOLOR=#CCCCFF align=center width=30>&nbsp;</td>
<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Name&nbsp;&nbsp;</strong></font></td>
<% 
'Customize this section if you need to display additional properties.
if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Entry Date&nbsp;&nbsp;</strong></font></td>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Document Class&nbsp;&nbsp;</strong></font></td>
	<td BGCOLOR=#CCCCFF align=right><font size=3><strong>&nbsp;&nbsp;Pages&nbsp;&nbsp;</strong></font></td>
<% else %>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Item ID&nbsp;&nbsp;</strong></font></td>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Document Class&nbsp;&nbsp;</strong></font></td>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Checkin Date&nbsp;&nbsp;</strong></font></td>
	<td BGCOLOR=#CCCCFF align=left><font size=3><strong>&nbsp;&nbsp;Author&nbsp;&nbsp;</strong></font></td>
<% end if %>
<td BGCOLOR=#CCCCFF align=center width=20>&nbsp;</td>
</tr>


<% 'Show all the subfolders first
for i=1 to Folders.Count %>
<tr>
<td valign=bottom align=right>
</td>

<td valign=bottom>
<% set FolderObj = Folders(i)
   fname = FolderObj.Label
%>
<% if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
<a HREF="javascript:ShowFolderContent('<%= fname %>')">
<img src="images/folder.gif" align=bottom border=0 width=32 height=32></a>
<% else %>
<a HREF="javascript:ShowFolderContent('<%= FolderObj.Id %>')">
<img <%if FolderObj.GetState(5) then %> src="images/repfolder.gif" <% else %> src="images/folder.gif" <% end if %> align=bottom border=0 width=32 height=32></a>
<% end if %>

<em><%= Server.HTMLEncode(fname)%></em>
</td>

<% 'Show folder properties
'Customize this section if you need to display additional properties.
if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= FolderObj.Properties("F_ENTRYDATE") %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	</font></td>
	<td valign=bottom align=right><font size=2>
	</font></td>
	<% if FolderObj.ID = 0 then %>
	<td></td>
	<% else %>
	<td valign=bottom><a HREF="javascript:ShowProperty(2,'<%= FolderObj.Pathname %>')">
	<img alt="'<%=fname%>' Properties" src="images/prop.gif" align=bottom border=0 width=16 height=21></a></td>
	<% end if %>
<% else %>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=right><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom><a HREF="javascript:ShowProperty(2,<%= FolderObj.Id %>)">
	<img alt="'<%=Server.HTMLEncode(fname)%>' Properties" src="images/prop.gif" align=bottom border=0 width=16 height=21></a></td>
<% end if %>
</tr>
<% next %>


<% 'If not at the root level, show all the documents within the folder.
	if IsFolder=1 then
      for i=1 to Docs.Count %>
<tr>
<td valign=bottom align=right>
<% set Doc = Docs(i) %>
<% if LibraryObj.SystemType = Application("idmSysTypeIS") then
		'See whether a document is annotated or not
		if Doc.GetState(Application("idmDocAnnotated")) and Application("ViewUsingNativeApplication") = False then %>
		   <img alt="Annotations" src="images/anno.gif" align=bottom border=0 width=27 height=24>
<%      end if
   else
		'See whether a document is checked out or not
		if Doc.GetState(Application("idmDocCheckedOut")) then %>
		   <img alt="CheckedOut" src="images/docckout.gif" align=bottom border=0 width=20 height=21>
<%      end if
end if %>
</td>

<td valign=bottom>
<% 'Display document ID with native Icon
docid = Doc.ID 
if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
  <a HREF="javascript:ShowDocument('<%=docid%>',<%=Doc.Properties("F_PAGES")%>)">
<% else %>
  <a HREF="javascript:ShowDocument('<%=docid%>',1)">
<% end if %>
<img src="<%=oDocUtil.IconFile(Doc)%>" align=bottom border=0 width=32 height=32></a>
<em><%=Server.HTMLEncode(Doc.Label)%></em>
</td>

<% 'Show document properties
'Customize this section if you need to display additional properties.
if LibraryObj.SystemType = Application("idmSysTypeIS") then %>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Doc.Properties("F_ENTRYDATE") %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Doc.Properties("F_DOCCLASSNAME") %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=right><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Doc.Properties("F_PAGES") %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
<% else %>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(docid) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(Doc.GetExtendedProperty("idmDocType")) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(Doc.GetExtendedProperty("idmVerCreateDate")) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
	<td valign=bottom align=left><font size=2>
	&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(Doc.GetExtendedProperty("idmVerCheckinUser")) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>	
<% end if

'Display the property page link %>
<td valign=bottom><a HREF="javascript:ShowProperty(1,'<%=docid%>')">
<img alt="'<%=Server.HTMLEncode(Doc.Label)%>' Properties" src="images/prop.gif" align=bottom border=0 width=16 height=21></a></td>
</tr>
<% next
   end if %>
</table>

</body>
</html>
